package com.color.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.color.dao.IUserNoDao;
import com.color.entity.UserNo;

@Repository("userNoDao")
public class UserNoDaoImpl extends HibernateBaseDao<UserNo> implements IUserNoDao {

	/**
	 * 删除
	 */
	public int Delete(UserNo usr) {
		return delete( usr);
	}
	
	/**
	 * 删除
	 */
	public void Delete(List<UserNo> usr) {
		if(usr != null){
			for(UserNo us : usr){
				delete(us);
			}
		}
	}
	
	/**
	 * 新增、修改
	 */
	public int Save(UserNo usr) {
		return save(usr);
	}
	
	/**
	 * 新增、修改
	 */
	public void Save(List<UserNo> usr) {
		if(usr != null){
			for(UserNo us : usr){
				save(us);
			}
		}
	}
	
	/**
	 * 总记录数
	 */
	public int getCountList(String sNo) {
		StringBuffer strHql = new StringBuffer();
		Map<String,Object> map = new HashMap<String,Object>();
		strHql.append(" select count(sId) as count from UserNo where 1=1 ");
		if(sNo != null && !"".equals(sNo)){
			strHql.append(" and sNo = :sNo ");
			map.put("sNo", sNo);
		}
		return openCountByHql(strHql.toString(),map);
	}

	/**
	 * 分页记录
	 */
	public List<UserNo> getPageList(int page, int size,String sNo) {
		StringBuffer strHql = new StringBuffer();
		Map<String,Object> map = new HashMap<String,Object>();
		
		strHql.append(" from UserNo where 1=1 ");
		
		if(sNo != null && !"".equals(sNo)){
			strHql.append(" and sNo = :sNo ");
			map.put("sNo", sNo);
		}
		strHql.append(" order by sNo desc,sId desc");
		List<UserNo> list = openHqlPage(strHql.toString(),page,size,map);
		return list;
	}
	
	/**
	 * 整期记录
	 */
	public List<UserNo> getColorList(String sNo) {
		StringBuffer strHql = new StringBuffer();
		Map<String,Object> map = new HashMap<String,Object>();
		
		strHql.append(" from UserNo where 1=1 ");
		
		if(sNo != null && !"".equals(sNo)){
			strHql.append(" and sNo = :sNo ");
			map.put("sNo", sNo);
		}
		strHql.append(" order by sNo desc,sId desc");
		List<UserNo> list = openHql(strHql.toString(),map);
		return list;
	}
	
	/**
	 * 获取最大记录
	 * @return
	 */
	public String getMaxUserNo(){
		StringBuffer strHql = new StringBuffer();
		strHql.append(" select max(sNo) from UserNo ");
		return openMaxByHql(strHql.toString());
	}

}
